#!/usr/bin/env python
# coding=utf-8
"""
@Author  : youjia - 卞志伟
@file    : week_report_member.py
@contact : bianzhiwei@iyoujia.com
@time    : 2019-06-28 17:12 
@Desc    : 会员月报
@Software: PyCharm
"""
import os
import sys

# 当前文件的路径
pwd, filename = os.path.split(os.path.abspath(__file__))
# 当前文件的父路径
father_path = os.path.abspath(os.path.dirname(pwd) + os.path.sep + ".")
# 当前文件的前两级目录
grader_father = os.path.abspath(os.path.dirname(pwd) + os.path.sep + "..")
sys.path.append(pwd)
sys.path.append(father_path)
sys.path.append(grader_father)

from report_system.utils import mail_util
from report_system.utils import mailbox_util
from report_system.utils.log_util import log
from report_system.report_specify.member_specify import cost_month
from report_system.report_specify.member_specify import recharge_month
from report_system.report_specify.member_specify import refund_month
from report_system.report_specify.member_specify import cashback_month
from report_system.report_specify.member_specify import free
from report_system.report_specify.member_specify import change_order_month
from report_system.utils.development_util import debug

if debug:
    receivers = 'dt@iyoujia.com'
    city_mails = None
else:
    receivers = 'lichunmei@iyoujia.com;liuxuejiao@city-home.cn;dt@iyoujia.com'
    city_mails = None


def process(st=None, et=None):
    cost_week_df = cost_month(st=st, et=et)
    log.info("一月的消费！")
    recharge_week_df = recharge_month(st=st, et=et)
    log.info("一月的 充值！")
    refund_week_df = refund_month(st=st, et=et)
    log.info("一月的 退款！")
    cashback_week_df = cashback_month(st=st, et=et)
    log.info("一月的 返现！")
    change_order_week_df = change_order_month(st=st, et=et)
    log.info("一月的 改派订单！")
    free_df = free()
    log.info("余额 截止当前日期所有")

    df_dict = {"月充值": recharge_week_df,
               "月消费": cost_week_df,
               "月退款": refund_week_df,
               "目前所有会员余额": free_df,
               "月返现": cashback_week_df,
               "月改派订单": change_order_week_df
               }

    text = """ Dear All:
                    附件是会员本月各项费用及改派订单！  
                    请查收！
                    谢谢！
            如有问题！
            请联系: dt@iyoujia.com
            """
    mail_util.distribute_mail(df_dict=df_dict, file_name='会员本月各项费用及改派订单', text=text,
                              title="会员本月各项费用及改派订单", receiver=receivers, na_rep='-', index=False, is_df=False)


def run():
    try:
        # process(st='2019-11-01', et='2019-11-30')
        process()
    except Exception as e:
        mail_util.error_mail("会员月报", e.__str__())
        log.exception(e)


if __name__ == '__main__':
    run()
